<?php
namespace App\Services\ExpressService;
/**
 * 物流配置
 *
 * 物流配置service
 *
 * @author    zhouchao <zhouchao@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */
use App\Services\Tool\DataBase\SQL;
use App\Services\Tool\GeneralTool;
use DB;
class ExpressService
{
    public function expressList($input){
        $per_page			= empty($input['per_page'])?10:$input['per_page'];
        $express			= SQL::paginate(array('table'=>'express',
            'where'=>array(),
            'order'=>'class',
            'per_page'=>$per_page));
        return $express;
    }

    public function addExpress($input){
        if(empty($input['express_name'])||empty($input['express_id'])||!isset($input['class'])){
            return GeneralTool::createResult('','M00002');
        }

        if(DB::table('express')->where($input)->count()>0){
            return GeneralTool::createREsult('','M03026');
        }

        $input['class']		= strtoupper($input['class']);
        $input['created_at']= time();
        $result				= DB::table('express')
            ->insert($input);
        return $result==1?GeneralTool::createResult('','M00000'):
            GeneralTool::createResult('','M00001');

    }

    public function delExpress($input){
        if(empty($input['id'])){
            return GeneralTool::createResult('','M05012');
        }

        if(DB::table('express')->where('id',$input['id'])->count()<1){
            return GenrealTool::createResult('','M03027');
        }

        $result				= DB::table('express')
            ->where('id',$input['id'])
            ->delete();
        return $result==1?GeneralTool::createResult('','M00000'):
            GeneralTool::createResult('','M00001');

    }
}